<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>
</head>
<body>
<div class="container">
    <form>
        <div class="form-group">
            <label for="exampleInputEmail1">Account</label>
            <input type="text" name="username" class="username form-control" id="exampleInputEmail1" aria-describedby="emailHelp">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword1">Password</label>
            <input type="password" name="pwd" class="pwd form-control" id="exampleInputPassword1">
        </div>
        <div class="form-group">
            <label for="exampleInputPassword2">验证码</label>
            <input type="text" name="code" class="code form-control" id="exampleInputPassword2">
        <div><img src="{:captcha_src()}" alt="captcha" /></div>
        </div>
        <button type="button" class="sub btn btn-primary">Submit</button>
    </form>
</div>
</body>
</html>
<script>
    $(".sub").on('click',function () {
        var username = $(".username").val();
        var pwd = $(".pwd").val();
        var code = $(".code").val();
        $.ajax({
            url:"http://www.week31.com/login",
            method:"post",
            data:{username:username,pwd:pwd,code:code},
            success:function (res) {
                alert(res.msg);
                if(res.code == 200){
                    window.location.href ="http://www.week31.com/main"
                }
            }
        })
    })
</script>